<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
session_start(); 
}  
include '../../operations/connection.php';
$sqlpartner = mysql_query("SELECT am.PartnerID,am.PartnerName,am.DomainName,am.DatabaseName,am.Phone,am.Email,am.Website,am.`Status`
		FROM `ac_eli_manager` am WHERE am.Role=2 and am.`Status` !=3; ");
$number_of_page = ceil ( mysql_num_rows( $sqlpartner ) / $rows_per_page ); 
?>
<script type="text/javascript">
$(document).ready(function(){
	document.getElementById("parnername").focus();
});
function enterTable(e,value){
    var key = window.event ? e.keyCode : e.which;
    if(key==13){
		var j = 0;
		var listID = new Array();
		listID = listID.concat(["parnername","password","repassword","databasename","domainname","email","phone","website","roothome"]);	
		for (j = 0; j < listID.length; j++){	
			if (listID[j] == value) {	
				if (j == listID.length - 1) {
					return false;
				}
				document.getElementById(listID[j + 1]).focus();
				document.getElementById(listID[j + 1]).select();
				return false; 
			}
		}
		
		return false;
	}else
		return true;	
				
}

function enterTable1(e,value){
    var key = window.event ? e.keyCode : e.which;
    if(key==13){
		var j = 0;
		var listID = new Array();
		listID = listID.concat(["parnername","email","phone","website"]);	
		for (j = 0; j < listID.length; j++){	
			if (listID[j] == value) {	
				if (j == listID.length - 1) {
					return false;
				}
				document.getElementById(listID[j + 1]).focus();
				document.getElementById(listID[j + 1]).select();
				return false; 
			}
		}
		
		return false;
	}else
		return true;	
				
}

function checkEmpty(){
	var partname = document.getElementById('parnername').value;
	var password = document.getElementById('password').value;
	var repassword = document.getElementById('repassword').value;
	var databasename = document.getElementById('databasename').value;
	var domainname = document.getElementById('domainname').value;
	var email = document.getElementById('email').value;
	var numberonechar = databasename.substr(0,1);

	if(partname.length==0){
		alert('Please input partner name');
		return false;
	}else if(password.length==0){
		alert('Please input password');
		return false;
	}else if(repassword.length==0){
		alert('Please input re-password');
		return false;
	}else if(password != repassword){
		alert('password or re-password is not correctly');
		return false;
	}else if(databasename.length==0){
		alert('Please input database name');
		return false;
	}else if(parseFloat(numberonechar).toString() == numberonechar){
		alert('First character must word');
		return false;
	}else if(databasename.length<2){
		alert('Database must least 2 characters ');
		return false;
	}else if(domainname.length==0){
		alert('Please input domain name');
		return false;
	}else if(domainname.indexOf('.')==1 || domainname.indexOf(',')==1 || domainname.indexOf(';')==1 || 
			domainname.indexOf(';')==1 || domainname.indexOf('?')==1){
		alert('Key domain name haven not special character');
		return false;
	}
	else if(email.length==0){
		alert('Please input email');
		return false;
	}
}
function checkEmpty1(){
	var partname = document.getElementById('parnername').value;
	var password = document.getElementById('password').value;
	var repassword = document.getElementById('repassword').value;
	var databasename = document.getElementById('databasename').value;
	var domainname = document.getElementById('domainname').value;
	var email = document.getElementById('email').value;
	var numberonechar = databasename.substr(0,1);

	if(partname.length==0){
		alert('<?=$l_alertpartername?>');
	}else if(password.length==0){
		alert('<?=$l_alertinputpass?>');
	}else if(repassword.length==0){
		alert('<?=$l_alertrepass?>');
	}else if(password != repassword){
		alert('<?=$l_alertpassandrepass?>');
	}else if(databasename.length==0){
		alert('<?=$l_alertinputdatabase?>');
	}else if(parseFloat(numberonechar).toString() == numberonechar){
		alert('<?=$l_alertwords?>');
	}else if(databasename.length<2){
		alert('<?=$l_alertdatasechar?>');
	}else if(domainname.length==0){
		alert('<?=$l_alertinputdomain?>');
	}else if(domainname.indexOf('.')==1 || domainname.indexOf(',')==1 || domainname.indexOf(';')==1 || 
			domainname.indexOf(';')==1 || domainname.indexOf('?')==1){
		alert('<?=$l_alertkeydomain?>');
	}
	else if(email.length==0){
		alert('<?=$l_alertemail?>');
	}else{
		return checktrung();
	}
}
function checktrung(){
	var partname = document.getElementById('parnername').value;
	var password = document.getElementById('password').value;
	var databasename = document.getElementById('databasename').value;
	var domainname = document.getElementById('domainname').value;
	var email = document.getElementById('email').value;
	var phone=document.getElementById('phone').value;
	var website=document.getElementById('website').value;
	var roothome = document.getElementById('roothome').value;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("idcheckdb_domain").innerHTML=xmlhttp.responseText;
										    	var lang = '<?=$_SESSION['lang']?>';
										    	$.ajax({url:"admin/partnermanage/ajaxviewketquathucthi.php?newlang="+lang,success:function(result){
													$("#idcheckdb_domain").html(result);
													var thongbao=document.getElementById("viewcheckdb_domain").value;
													if(thongbao=="okk"){
														alert(thongbao);
														if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
															xmlhttp=new XMLHttpRequest();
														}else{// code for IE6, IE5
															xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
														}
														xmlhttp.onreadystatechange=function(){
																							  if (xmlhttp.readyState==4 && xmlhttp.status==200){
																							    	document.getElementById("tbcomp").innerHTML=xmlhttp.responseText;
																							    	reset();
																							  }
																						  }
														xmlhttp.open("GET","admin/partnermanage/ajaxadd.php?register=add&parnername="+partname+"&password="+password+"&databasename="+databasename+"&email="+email+"&phone="+phone+"&website="+website+"&domainname="+domainname+"&roothome="+roothome,true);
														xmlhttp.send();
													}else{
														alert(thongbao);
														//return false;
													}
										    	}});
										    	
										  }
									  }
	xmlhttp.open("GET","admin/partnermanage/ajaxcheckdb_domain.php?pname="+partname+"&db="+databasename+"&domain="+domainname,true);
	xmlhttp.send();
}


function checkEmptyUpdate(){
	var partname = document.getElementById('parnername').value;
	var email = document.getElementById('email').value;

	if(partname.length==0){
		alert('Please input partner name');
		return false;
	}
	else if(email.length==0){
		alert('Please input email');
		return false;
	}
}
function reset(){
	document.getElementById('parnername').value = "";
	document.getElementById('password').value = "";
	document.getElementById('repassword').value = "";
	document.getElementById('databasename').value = "";
	document.getElementById('email').value ="";
	document.getElementById('phone').value ="";
	document.getElementById('website').value ="" ;
	document.getElementById('domainname').value="";
	document.getElementById("parnername").focus();
	document.getElementById("roothome").value= "";
}

function resetchildPartner(){
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {

	        document.getElementById("infor_body").innerHTML=xmlhttp.responseText;
	        document.getElementById("parnername").focus();
	        
	    }
	  }
	var lang = '<?=$_SESSION['lang']?>';
	$('input:checkbox').removeAttr('checked');
	
	xmlhttp.open("GET","admin/partnermanage/resetchildpartner.php?newlang="+lang,true);
	xmlhttp.send();
}
function processCheck(tenid,field){
	if(document.getElementById(tenid).checked == true){
		for(var i = 0;i<field.length;i++)
	    {
			field[i].checked = false ;
	    }
		document.getElementById(tenid).checked = true;
	 	var gtid=document.getElementById(tenid).value;
	 	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
	 		xmlhttp=new XMLHttpRequest();
	 	}else{// code for IE6, IE5
	 		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	 	}
	 	xmlhttp.onreadystatechange=function(){
			 	if (xmlhttp.readyState==4 && xmlhttp.status==200){
			 		document.getElementById("infor_body").innerHTML=xmlhttp.responseText;
			 	}
		 	}
	 	var lang = '<?=$_SESSION['lang']?>';
	 	xmlhttp.open("GET","admin/partnermanage/view-account-comp.php?idcomp="+gtid+"&newlang="+lang,true);
	 	xmlhttp.send();
	}else{
		document.getElementById(tenid).checked=false;
		//reset();
		resetchildPartner();
	}
}
function deletecomp(id,els){
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {

	        document.getElementById("tbcomp").innerHTML=xmlhttp.responseText;
	        
	    }
	  }
	var lang = '<?=$_SESSION['lang']?>';
	reset();
	$('input:checkbox').removeAttr('checked');
	
	document.getElementById('update').style.visibility='hidden';
	document.getElementById('update').style.display='none';
	document.getElementById('delete').style.visibility='hidden';
	document.getElementById('delete').style.display='none';
	document.getElementById('register').setAttribute("class", "buttonNormal");
	document.getElementById('register').setAttribute("type", "submit");
	$("#password").removeAttr('readonly');
	document.getElementById('password').style.backgroundColor ="#ffffff";
	$("#repassword").removeAttr('readonly');
	document.getElementById('repassword').style.backgroundColor ="#ffffff";
	$("#databasename").removeAttr('readonly');
	document.getElementById('databasename').style.backgroundColor ="#ffffff";
	$("#domainname").removeAttr('readonly');
	document.getElementById('domainname').style.backgroundColor ="#ffffff";
	
	xmlhttp.open("GET","admin/partnermanage/process-delete-comp.php?idcomp="+id+"&newlang="+lang,true);
	xmlhttp.send();

	
}

function pagingcomp(page){
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	    {

	        document.getElementById("tbcomp").innerHTML=xmlhttp.responseText;
	        
	    }
	  }
	var lang = '<?=$_SESSION['lang']?>';
	reset();
	$('input:checkbox').removeAttr('checked');
	
	xmlhttp.open("GET","admin/partnermanage/paging-comp.php?page="+page,true);
	xmlhttp.send();
}
</script>
<script type="text/javascript">
$(document).ready(function(){
	<?php 
	if (isset($_SESSION['insertpartner'])){?>
		alert("<?php echo $l_themthanhcong?>");
	<?php unset($_SESSION['insertpartner']);}
	?>

	<?php 
			if (isset($_SESSION['updatepartner'])){?>
				alert("<?php echo $l_capnhatthanhcong?>");
			<?php unset($_SESSION['updatepartner']);}
			?>

			<?php 
					if (isset($_SESSION['deletepartner'])){?>
						alert("<?php echo $l_xoathanhcong?>");
					<?php unset($_SESSION['deletepartner']);}
					?>


});

</script>
<style>
input,select,textarea {
	font-family: Arial, Verdana, sans-serif;
	font-size: 13px !important;
}
</style>
<div id="contains" style="background: #edf4f7;">
	<div class="title"></div>
	<div style="height: 10px;"></div>
	<div class="body" id="contentHome">
		<div id="idcheckdb_domain">
			<input type="hidden" id="viewcheckdb_domain" value="<?=$_SESSION['checkdb_domain']?>" />
		</div>
		<div class="rf-p " id="infor" style="width: 98%; margin-left: 5px;">

			<div class="rf-p-hdr " id="infor_header"
				style="font-family: Arial, Verdana, sans-serif; font-size: 12px !important;">
				<?php echo $l_createnewacccomp?>
			</div>
			<div class="rf-p-b " id="infor_body">
				<form action="admin/partnermanage/process-add-partner-manage.php"
	 method="post">
					
					<table align="center">
						<tbody>
							<tr style="height: 21px;">
								<td style="width: 30%"><?php echo $l_doitac?>: <span style="color: red">( * )</span></td>
								<td style="width: 70%"><input onkeypress="return enterTable(event,this.id);" id="parnername" name="parnername" type="text"
									value=""  style="height: 21px;width: 100%;border: 1px solid #c4c6c9;" autocomplete="off" /></td>
							</tr>
							<tr style="height: 21px;">
								<td><?php echo $l_passwordLBL?> <span style="color: red">( * )</span></td>
								<td><input  onkeypress="return enterTable(event,this.id);" type="password" id="password" name="password"
									 style="height: 21px;width: 100%;border: 1px solid #c4c6c9;" value="" autocomplete="off"/></td>
							</tr>
							<tr style="height: 21px;">
								<td><?php echo $l_retypepassword?> : <span style="color: red">( * )</span></td>
								<td><input onkeypress="return enterTable(event,this.id);" type="password" id="repassword" name="repassword"
									 style="height: 21px;width: 100%;border: 1px solid #c4c6c9;" value="" autocomplete="off"/></td>
							</tr>
							<tr style="height: 21px;">
								<td><?php echo $l_databasename?> : <span style="color: red">( * )</span></td>
								<td><input  onkeypress="return enterTable(event,this.id);" id="databasename" name="databasename" type="text"
									value=""  style="height: 21px;width: 100%;border: 1px solid #c4c6c9;" />
								</td>
							</tr>
							<tr style="height: 21px;">
								<td><?php echo $l_domainame?> : <span style="color: red">( * )</span></td>
								<td>
									<input  onkeypress="return enterTable(event,this.id);" id="domainname" name="domainname" type="text"  value=""  style="height: 21px;width: 29%;border: 1px solid #c4c6c9;" />
									<input value="." style="width: 1%;border: none;font-weight: bold;text-align: center;">
									<input id="enddatabasename" name="enddatabasename"  type="text" value="myapprove.com" style="height: 21px;width: 68%;background: #eee;float: right;border: 1px solid #c4c6c9;" readonly="readonly"/>
								</td>
							</tr>
							<tr style="height: 21px;">
								<td><?php echo $l_email?> : <span style="color: red">( * )</span></td>
								<td><input  onkeypress="return enterTable(event,this.id);" id="email" name="email" type="text" value=""
									 style="height: 21px;width: 100%;border: 1px solid #c4c6c9;" />
								</td>
							</tr>
							<tr style="height: 21px;">
								<td><?php echo $l_phone?> :</td>
								<td><input  onkeypress="return enterTable(event,this.id);" id="phone" name="phone" type="text" value=""
									 style="height: 21px;width: 100%;border: 1px solid #c4c6c9;" />
								</td>
								<td></td>
							</tr>
							<tr style="height: 21px;">
								<td><?php echo $l_Website?> :</td>
								<td><input  onkeypress="return enterTable(event,this.id);" id="website" name="website" type="text" value=""
									 style="height: 21px;width: 100%;border: 1px solid #c4c6c9;" /></td>
								<td></td>
							</tr>
							<tr style="height: 21px;">
								<td><?php echo $l_roothome?> :</td>
								<td><input  onkeypress="return enterTable(event,this.id);" id="roothome" name="roothome" type="text" value=""
									 style="height: 21px;width: 100%;border: 1px solid #c4c6c9;" /></td>
								<td></td>
							</tr>
						</tbody>
					</table>

					<br />
					<div style="text-align: center;">
					<input name="update" id="update" value="<?php echo $l_update?>" class="buttonNormal" type="button" style="display: none;visibility: hidden;"/> 
					<input name="delete" id="delete" value="<?php echo $l_delete?>" class="buttonNormal" type="button" style="display: none;visibility: hidden;"/> 
						<input name="register" id="register" value="<?php echo $l_register?>"
							class="buttonNormal" type="button" onclick="checkEmpty1();";  /> 
					<input name="reset"
							value="<?php echo $l_reset?>" class="buttonNormal" type="reset"
							onclick="reset();" /> <br />
					</div>
				</form>
			</div>

			<div style="height: 30px;"></div>
			<div id="tbcomp">
			<form action="#" name="formCheck" method="post">
				<table id="listRequest" class="rf-dt" style="width: 100%;">
					<thead class="rf-dt-thd">
						<tr class="rf-dt-shdr">
							<th class="rf-dt-shdr-c" scope="col"
								style="background-color: #eeeeee; width: 3%; font-size: 12px;">
							</th>
							<th class="rf-dt-shdr-c" scope="col"
								style="background-color: #eeeeee; width: 20%; font-size: 12px;"><?php echo $l_doitac?>
							</th>
							<th class="rf-dt-shdr-c" scope="col"
								style="background-color: #eeeeee; width: 15%; font-size: 12px;"><?php echo $l_domainame?>
							</th>
							<th class="rf-dt-shdr-c" scope="col"
								style="background-color: #eeeeee; width: 13%; font-size: 12px;"><?php echo $l_databasename?>
							</th>
							<th class="rf-dt-shdr-c" scope="col"
								style="background-color: #eeeeee; width: 9%; font-size: 12px;"><?php echo $l_phone?>
							</th>
							<th class="rf-dt-shdr-c" scope="col"
								style="background-color: #eeeeee; width: 15%; font-size: 12px;"><?php echo $l_email?>
							</th>
							<th class="rf-dt-shdr-c" scope="col"
								style="background-color: #eeeeee; width: 15%; font-size: 12px;"><?php echo $l_Website?>
							</th>
							<th class="rf-dt-shdr-c" scope="col"
								style="background-color: #eeeeee; width: 23%; font-size: 12px;"><?php echo $l_status?>
							</th>
						</tr>
						<?php
						if(mysql_num_rows($sqlpartner)>0){
							$i=0;
							while ($row = mysql_fetch_array($sqlpartner)){
								if ( $i >= $page_start ){
									?>
						<tr>
							<td class="rf-dt-shdr-c" scope="col"
								style="background-color: #ffffff; width: 3%; font-weight: normal; font-size: 12px;">
								<input type="checkbox" name="checkname"
								id="<?php echo 'checkcus'.$i?>"
								onclick="processCheck(this.id,document.formCheck.checkname);"
								value="<?=$row[PartnerID]?>" />
							</td>
							<td class="rf-dt-shdr-c" scope="col"
								style="background-color: #ffffff; width: 20%; font-weight: normal; font-size: 12px;"><?php echo $row[PartnerName]?>
							</td>
							<td class="rf-dt-shdr-c" scope="col"
								style="background-color: #ffffff; width: 15%; font-weight: normal; font-size: 12px;">
								<a href="<?php echo "http://".$row[DomainName]?>" target="_blank"><?php echo $row[DomainName]?></a>
							</td>
							<td class="rf-dt-shdr-c" scope="col"
								style="background-color: #ffffff; width: 13%; font-weight: normal; font-size: 12px;"><?php echo $row[DatabaseName]?>
							</td>
							<td class="rf-dt-shdr-c" scope="col"
								style="background-color: #ffffff; width: 9%; font-weight: normal; font-size: 12px;"><?php echo $row[Phone]?>
							</td>
							<td class="rf-dt-shdr-c" scope="col"
								style="background-color: #ffffff; width: 15%; font-weight: normal; font-size: 12px;"><?php echo $row[Email]?>
							</td>
							<td class="rf-dt-shdr-c" scope="col"
								style="background-color: #ffffff; width: 15%; font-weight: normal; font-size: 12px;">
								<a href="<?php echo "http://".$row[Website]?>" target="_blank"><?php echo $row[Website]?></a>
							</td>
							<td class="rf-dt-shdr-c" scope="col"
								style="background-color: #ffffff; width: 23%; font-weight: normal; font-size: 12px;">
								<?php if($row[Status]==2){ echo $l_danghoatdong;}else{echo $l_ngunghoatdong;}?>
							</td>
						</tr>
						<?php
								}
								$i++;
								if ($i >= $page_end){
									break;
								}
							}
						}
						?>

<tr>
						<td colspan="8" class="rf-dt-shdr-c">
							<span style="background:#fff; padding:1px; display: inline-block;">
														
								<?php if ( $number_of_page > 1 ) 
								{ 
									if ($page==1)
										$p=2;
									else if ($page==$number_of_page)
										$p=$number_of_page-1;
									else $p=$page;
									if($page!=1){?>
										<a onclick="pagingcomp(1);" ><span class='button_next'><?php echo "<<<";?></span> </a>
										<a onclick="pagingcomp(<?=($page-1)?>);" ><span class='button_next'><?php echo "<<";?></span> </a>
									<?php  }
									else{
										echo "<span class='button_next'><<<</span> "; 
										echo "<span class='button_next'><<</span> ";
									}
									for ( $i = $p-1; $i <= $p+1; $i++ ) {	
											if ($i<=$number_of_page && $i>0)
											
												if ($i==$page){
													echo "<span class='button_next'><b>".$i."</b></span>"; 
												}else{
												?>
													<a onclick="pagingcomp(<?=$i?>);" ><span class="button_next">
													<?php 
													echo $i;
													?>
													</span> </a>
													<?php 
												}
											?>
										
									<?php 
											}
										
										if($page!=$number_of_page){ ?>
											<a onclick="pagingcomp(<?=($page+1)?>);"><span class='button_next'><?php echo ">>";?></span> </a>
											<a onclick="pagingcomp(<?=($number_of_page)?>);" ><span class='button_next'><?php echo ">>>";?></span> </a>
										<?php }
										else{
											echo "<span class='button_next'>>></span> ";
											echo "<span class='button_next'>>>></span> ";
										}
									}
								
									
									?>
																						
							</span>
						</td>
					</tr>
					</thead>
				</table>
			</form>
			</div>
		</div>
		
	</div>
</div>
